package com.matt.controller.api.web;

import com.matt.commons.dto.sso.StaffDTO;
import com.matt.domain.Leads;
import com.matt.domain.LeadsUser;
import com.matt.foundation.constant.PermissionConstant;
import com.matt.foundation.model.StatusResponse;
import com.matt.foundation.query.LeadsQuery;
import com.matt.remoteCall.SsoCallService;
import com.matt.service.LeadsUserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/web/leadsUser")
@Api(tags = "CRM - 线索")
public class LeadsUserController {
    @Autowired
    private LeadsUserService leadsUserService;
    @Autowired
    private SsoCallService ssoCallService;

    /**
     * 添加联系人
     *
     * @param ticket
     * @param leadsUser
     * @return
     */
    @RequestMapping(value = "/add")
    public StatusResponse add(@RequestHeader String ticket, LeadsUser leadsUser) {
        return StatusResponse.success(leadsUserService.save(leadsUser, ticket));
    }

    /**
     * 编辑联系人
     *
     * @param ticket
     * @param leadsUser
     * @return
     */
    @RequestMapping(value = "/update")
    public StatusResponse update(@RequestHeader String ticket, LeadsUser leadsUser) {
        return StatusResponse.success(leadsUserService.update(leadsUser, ticket));
    }

    /**
     * 修改为第一联系人
     *
     * @param ticket
     * @param leadsUser
     * @return
     */
    @RequestMapping(value = "/editType")
    public StatusResponse editType(@RequestHeader String ticket, LeadsUser leadsUser) {
        return StatusResponse.success(leadsUserService.editType(leadsUser, ticket));
    }

    /**
     * 查询全部线索/我的线索
     *
     * @param
     * @param
     * @return
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public StatusResponse leadsByInfo(@RequestHeader String ticket, LeadsUser leadsUser) {

        StaffDTO staff = ssoCallService.getStaffDTO(ticket);
        leadsUser.setAreaId(staff.getAreaId());
        List<LeadsUser> voList=leadsUserService.leadsByInfo(staff,leadsUser);
        return StatusResponse.success(voList);
    }
}
